package com.tgy.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.tgy.entity.Student;
import com.tgy.service.StudentService;
import com.tgy.service.impl.StudentServiceImpl;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Map;

/**
 * (Student)表控制层
 *
 * @author makejava
 * @since 2021-08-29 14:48:19
 */

//@CrossOrigin(origins = "*", maxAge = 3600)

@RestController
@RequestMapping("/student")
public class StudentDoController {
    /**
     * 服务对象
     */
    @Resource
    private StudentService studentService;
    @Resource
    private StudentServiceImpl studentServiceImpl;

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("selectOne")
    public Student selectOne(Integer id) {
        return this.studentService.queryById(id);
    }

    @RequestMapping(value = "/getStudentList.do")
    public Map<String, Object> getStudentList(Student student) {
        return studentService.queryAll(student);
    }

    //添加学生接口
    @RequestMapping(value = "/addStudent.do")
    public String addStudent(Student student) {
        studentService.insert(student);
        return "添加学生接口";
    }

    //删除学生接口
    @RequestMapping("delStudentById.do")
    public String delStudentById(int id){
        if(studentService.deleteById(id)){
            return "删除学生接口";
        }else {
            return null;
        }
    }

    //修改学生接口
    @RequestMapping(value = "/updStudent.do")
    public String updStudent(Student student) {
        studentService.update(student);
        return "修改学生接口";
    }

    //查询的后端分页
    @RequestMapping(value = "/getStudentList")
    public PageInfo<Student> getStudentListPage(Student student,int pageNum, int pageSize) {
        return studentServiceImpl.queryAllByPage(student,pageNum,pageSize);
    }

}
